#include "infopacket.h"

InfoPacket::InfoPacket()
{

}
void InfoPacket::Decode2Map(QString JSONdata)
{
    Packet_Info.clear();
    QJsonDocument QJson;
    QJson.fromJson(JSONdata.toUtf8());
    if(QJson.isObject())
    {
        if(QJson.object().contains("Type"))
        {
            Packet_Info.insert("Type",QJson.object().value("Type"));
            if(Packet_Info["Type"] == "RIGISTER")
            {
                Packet_Info.insert("name",QJson.object().value("name"));
                Packet_Info.insert("passwd",QJson.object().value("name"));
            }
            if(Packet_Info["Type"] == "CHECK")
            {
                Packet_Info.insert("phone_num",QJson.object().value("phone_num"));
            }
            if(Packet_Info["Type"] == "RETURN_CHECK")
            {
                Packet_Info.insert("uid_me",QJson.object().value("uid_me"));
                Packet_Info.insert("check_num",QJson.object().value("check_num"));
            }
            if(Packet_Info["Type"] == "LOGIN")
            {
                Packet_Info.insert("uid_me",QJson.object().value("uid_me"));
                Packet_Info.insert("passwd",QJson.object().value("passwd"));
            }
            if(Packet_Info["Type"] == "ADD_FRIEND")
            {
                Packet_Info.insert("uid_me",QJson.object().value("uid_me"));
                Packet_Info.insert("friend_uid_list",QJson.object().value("friend_uid_group"));
            }
            if(Packet_Info["Type"] == "MESSAGE")
            {
                Packet_Info.insert("uid_me",QJson.object().value("uid_me"));
                Packet_Info.insert("uid_group",QJson.object().value("uid_group"));
                Packet_Info.insert("Msg",QJson.object().value("Msg"));
            }
            if(Packet_Info["Type"] == "MESSAGE_SYNC")
            {
                Packet_Info.insert("uid_me",QJson.object().value("uid_me"));
            }
        }
    }
}
